package com.gaswell.canal.aware;

import com.gaswell.canal.AbastractCanalOperator;
import com.gaswell.common.utils.R;
import com.gaswell.mapper.DiagnosisNewMapper;
import com.gaswell.mapper.ParamsMapper;
import com.gaswell.pojo.Params;
import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.Aware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
public class MyAwarePostprocessor implements BeanPostProcessor {
    @Autowired
    private DiagnosisNewMapper diagnosisNewMapper;
    @Autowired
    private ParamsMapper paramsMapper;


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

        if (bean instanceof MyAware) {
            if (bean instanceof AbastractCanalOperator) {
                Params n_all_well = paramsMapper.selectByNameaAndJh("失真-报警数", "all_well");
                Params m_all_well1 = paramsMapper.selectByNameaAndJh("失真-追溯数", "all_well");
                if (n_all_well != null)
                    ((MyAware) bean).setN((int) n_all_well.getParam_value());
                if (m_all_well1 != null)
                    ((MyAware) bean).setM((int) m_all_well1.getParam_value());
            }
        }
        return bean;
    }

}